Stygian = Stygian or {}
Stygian.info = Stygian.info or {}
Stygian.info.fontSize = 10
Stygian.info.fontWidth, Stygian.info.fontHeight = calcFontSize(Stygian.info.fontSize)
mainWidth, mainHeight = getMainWindowSize()
Stygian.info.width = 300
Stygian.info.height = Stygian.info.fontHeight * 39
Stygian.info.wordwrap = (Stygian.info.width / Stygian.info.fontWidth)
Stygian.info.posX = 0
Stygian.info.posY = Stygian.calendar.height + Stygian.calendar.herbHeight + 25
Stygian.items = Stygian.items or {}
Stygian.items.liquid = Stygian.items.liquid or {}
Stygian.herbs = Stygian.herbs or {}
Stygian.herbs.curing = Stygian.herbs.curing or {}
Stygian.herbs.functional = Stygian.herbs.functional or {}
 
infoTable = {
        "Potion",
        "Magic",
        "Pipes",
        "Herbs",
        "Astro",
        "Tar",
        "Aff",
        }
 
Stygian.info.tabWidth, Stygian.info.tabHeight = math.floor( Stygian.info.width / table.getn( infoTable ) ), 25
Stygian.info.tabPosX, Stygian.info.tabPosY = Stygian.info.posX, Stygian.info.posY - 25
 
-- Functions
function Stygian_infoCreate ()
        local startX = Stygian.info.tabPosX
        for _,v in ipairs( infoTable ) do
                local tab = "tab" .. v
                createLabel( tab, startX, Stygian.info.tabPosY, Stygian.info.tabWidth, Stygian.info.tabHeight, 0 )
                resizeWindow( tab, Stygian.info.tabWidth, Stygian.info.tabHeight )
                setLabelClickCallback( tab, "switchinfo", v )
                echo( tab, [[<center><font color="white">]] .. v .. [[</font></center></b></p>]] )
                moveWindow( tab, startX, Stygian.info.tabPosY )
                startX = startX + Stygian.info.tabWidth
 
                local info = "info" .. v
                createMiniConsole( info, Stygian.info.posX, Stygian.info.posY, Stygian.info.width, Stygian.info.height )
                resizeWindow( info, Stygian.info.width, Stygian.info.height )
                setWindowWrap( info, Stygian.info.wordwrap )
                setMiniConsoleFontSize( info, Stygian.info.fontSize )
                setBackgroundColor( info, 0, 0, 0, 0 )
                moveWindow( info, Stygian.info.posX, Stygian.info.posY )
                hideWindow( info )
        end
        Stygian.info.currentTab = "none"
        switchinfo( "All" )
end
 
function switchinfo ( info )
        local o_c = "info" .. Stygian.info.currentTab
        local o_t = "tab" .. Stygian.info.currentTab
        local n_c = "info" .. info
        local n_t = "tab" .. info
        if Stygian.info.currentTab ~= info then
                hideWindow( o_c )
                showWindow( n_c )
                Stygian.info.currentTab = info
                setBackgroundColor( o_t, 0, 0, 0, 0 )
                setBackgroundColor( n_t, 100, 100, 100, 125 )
        end
end

function Stygian_infoResize()
  Stygian.info.fontWidth, Stygian.info.fontHeight = calcFontSize(Stygian.info.fontSize)
  mainWidth, mainHeight = getMainWindowSize()
  Stygian.info.height = Stygian.info.fontHeight * 39
  Stygian.info.wordwrap = (Stygian.info.width / Stygian.info.fontWidth) 
  Stygian.info.posX = 0
  Stygian.info.posY = Stygian.calendar.height + Stygian.calendar.herbHeight + 25
  Stygian_infoCreate()
end 

if not Stygian.info.initialized then
	Stygian_infoCreate()
	Stygian.info.initialized = true
end

function Stygian_potionPrint(pot1, pot2)
  local type1 = ""
  local type2 = ""
  local amount1 = ""
  local amount2 = ""
  if pot2 then 
    if string.len(pot1) < 12 then
      type1 = align(string.title(pot1), {width = 12, alignment = "left"})
    else
      type1 = string.title(pot1)
    end
    if string.len(pot2) < 12 then
      type2 = align(string.title(pot2), {width = 12, alignment = "left"})
    else
      type2 = string.title(pot2)
    end
    if Stygian.items.liquid[pot1] then 
      amount1 = Stygian.items.liquid[pot1].sips or 0
    else
      amount1 = 0
    end
    if Stygian.items.liquid[pot2] then
      amount2 = Stygian.items.liquid[pot2].sips or 0
    else
      amount2 = 0
    end
    local spacer = string.rep(" ", 5 - string.len(amount1))
    return string.format("<green>%s:<red>%s%s<green>%s:<red>%s\n",type1, amount1, spacer, type2, amount2)
  else
    if string.len(pot1) < 12 then
      type1 = align(string.title(pot1), {width = 12, alignment = "left"})
    else
      type1 = string.title(pot1)
    end
    if Stygian.items.liquid[pot1] then 
      amount1 = Stygian.items.liquid[pot1].sips or 0
    else 
      amount1 = 0
    end
    return string.format("<green>%s:<red>%s\n", type1, amount1)
  end
end

function Stygian_updatePotions()
  clearWindow("infoPotion")
  cecho("infoPotion", "<purple>Healing/Mana/Bromides\n" )
  cecho("infoPotion", Stygian_potionPrint("healing", "mana"))
  cecho("infoPotion", Stygian_potionPrint("bromides"))
  cecho("infoPotion", "<purple>Potions and Salves\n")
  cecho("infoPotion", Stygian_potionPrint("antidote", "liniment"))
  cecho("infoPotion", Stygian_potionPrint("fire", "frost"))
  cecho("infoPotion", Stygian_potionPrint("love", "mending"))
  cecho("infoPotion", Stygian_potionPrint("regeneration"))
  cecho("infoPotion", "<purple>Purgatives\n")
  cecho("infoPotion", Stygian_potionPrint("choleric", "melancholic"))
  cecho("infoPotion", Stygian_potionPrint("phlegmatic", "sanguine"))
  cecho("infoPotion", "<purple>Influence Oils\n")
  cecho("infoPotion", Stygian_potionPrint("jasmine", "sandalwood"))
  cecho("infoPotion", Stygian_potionPrint("musk", "vanilla"))
  cecho("infoPotion", Stygian_potionPrint("dragonsblood"))
  cecho("infoPotion", "<purple>Utility Oils\n")
  cecho("infoPotion", Stygian_potionPrint("preservation", "sharpness"))
  cecho("infoPotion", Stygian_potionPrint("invisibility"))
  cecho("infoPotion", "<purple>\nPoisons\n")
  cecho("infoPotion", Stygian_potionPrint("aleutian", "anatine"))
  cecho("infoPotion", Stygian_potionPrint("anerod", "botulinum"))
  cecho("infoPotion", Stygian_potionPrint("calcise", "chansu"))
  cecho("infoPotion", Stygian_potionPrint("charybdon", "contortrin"))
  cecho("infoPotion", Stygian_potionPrint("crotamine", "dendroxin"))
  cecho("infoPotion", Stygian_potionPrint("dulak", "escozul"))
  cecho("infoPotion", Stygian_potionPrint("hadrudin", "haemotox"))
  cecho("infoPotion", Stygian_potionPrint("ibululu", "inyoka"))
  cecho("infoPotion", Stygian_potionPrint("mactans", "mantakaya"))
  cecho("infoPotion", Stygian_potionPrint("mellitin", "morphite"))
  cecho("infoPotion", Stygian_potionPrint("niricol", "pyrotoxin"))
  cecho("infoPotion", Stygian_potionPrint("saxitin", "senso"))
  cecho("infoPotion", Stygian_potionPrint("tetrodin"))
end

function Stygian_magicPrint(pot1, pot2)
  local type1 = ""
  local type2 = ""
  local amount1 = ""
  local amount2 = ""
  if pot2 then 
    if string.len(pot1) < 12 then
      type1 = align(string.title(pot1), {width = 12, alignment = "left"})
    else
      type1 = string.title(pot1)
    end
    if string.len(pot2) < 12 then
      type2 = align(string.title(pot2), {width = 12, alignment = "left"})
    else
      type2 = string.title(pot2)
    end
    if Stygian.items.magic[pot1] then 
      amount1 = Stygian.items.magic[pot1].charges or 0
    else
      amount1 = 0
    end
    if Stygian.items.magic[pot2] then
      amount2 = Stygian.items.magic[pot2].charges or 0
    else
      amount2 = 0
    end
    local spacer = string.rep(" ", 5 - string.len(amount1))
    return string.format("<green>%s:<red>%s%s<green>%s:<red>%s\n",type1, amount1, spacer, type2, amount2)
  else
    if string.len(pot1) < 12 then
      type1 = align(string.title(pot1), {width = 12, alignment = "left"})
    else
      type1 = string.title(pot1)
    end
    if Stygian.items.magic[pot1] then 
      amount1 = Stygian.items.magic[pot1].charges or 0
    else 
      amount1 = 0
    end
    return string.format("<green>%s:<red>%s\n", type1, amount1)
  end
end
function Stygian_updateMagic()
  clearWindow("infoMagic")
  cecho("infoMagic", Stygian_magicPrint("healing", "protection"))
  cecho("infoMagic", Stygian_magicPrint("gust", "ignite"))
  cecho("infoMagic", Stygian_magicPrint("geyser", "web"))
  cecho("infoMagic", Stygian_magicPrint("scry", "dig"))
  cecho("infoMagic", Stygian_magicPrint("mercy", "kingdom"))
  cecho("infoMagic", Stygian_magicPrint("beauty", "perfection"))
  cecho("infoMagic", Stygian_magicPrint("waterwalk"))
end

function Stygian_pipePrint(pipe)
 cecho("infoPipes", string.format("<green>%s:<red> %s\n", align(string.title(pipe), {alignment = "left", width = 12}), Stygian.items.pipes[pipe].puffs)) 
end

function Stygian_updatePipes()
  clearWindow("infoPipes")
  Stygian_pipePrint("myrtle")
  Stygian_pipePrint("faeleaf")
  Stygian_pipePrint("coltsfoot")
end

function Stygian_curingHerbPrint(herb1, herb2)
  local type1 = ""
  local type2 = ""
  local amount1 = ""
  local amount2 = ""
  if herb2 then 
    if string.len(herb1) < 12 then
      type1 = align(string.title(herb1), {width = 12, alignment = "left"})
    else
      type1 = string.title(herb1)
    end
    if string.len(herb2) < 12 then
      type2 = align(string.title(herb2), {width = 12, alignment = "left"})
    else
      type2 = string.title(herb2)
    end
    if Stygian.herbs.curing[herb1] then 
      amount1 = Stygian.herbs.curing[herb1] or 0
    else
      amount1 = 0
    end
    if Stygian.herbs.curing[herb2] then
      amount2 = Stygian.herbs.curing[herb2] or 0
    else
      amount2 = 0
    end
    local spacer = string.rep(" ", 5 - string.len(amount1))
    return string.format("<green>%s:<red>%s%s<green>%s:<red>%s\n",type1, amount1, spacer, type2, amount2)
  else
    if string.len(herb1) < 12 then
      type1 = align(string.title(herb1), {width = 12, alignment = "left"})
    else
      type1 = string.title(herb1)
    end
    if Stygian.herbs.curing[herb1] then 
      amount1 = Stygian.herbs.curing[herb1] or 0
    else 
      amount1 = 0
    end
    return string.format("<green>%s:<red>%s\n", type1, amount1)
  end
end

function Stygian_functionalHerbPrint(herb1, herb2)
  local type1 = ""
  local type2 = ""
  local amount1 = ""
  local amount2 = ""
  if herb2 then 
    if string.len(herb1) < 12 then
      type1 = align(string.title(herb1), {width = 12, alignment = "left"})
    else
      type1 = string.title(herb1)
    end
    if string.len(herb2) < 12 then
      type2 = align(string.title(herb2), {width = 12, alignment = "left"})
    else
      type2 = string.title(herb2)
    end
    if Stygian.herbs.functional[herb1] then 
      amount1 = Stygian.herbs.functional[herb1] or 0
    else
      amount1 = 0
    end
    if Stygian.herbs.functional[herb2] then
      amount2 = Stygian.herbs.functional[herb2] or 0
    else
      amount2 = 0
    end
    local spacer = string.rep(" ", 5 - string.len(amount1))
    return string.format("<green>%s:<red>%s%s<green>%s:<red>%s\n",type1, amount1, spacer, type2, amount2)
  else
    if string.len(herb1) < 12 then
      type1 = align(string.title(herb1), {width = 12, alignment = "left"})
    else
      type1 = string.title(herb1)
    end
    if Stygian.herbs.functional[herb1] then 
      amount1 = Stygian.herbs.functional[herb1] or 0
    else 
      amount1 = 0
    end
    return string.format("<green>%s:<red>%s\n", type1, amount1)
  end
end

function Stygian_updateHerbs()
  clearWindow("infoHerbs")
  cecho("infoHerbs", string.format("<purple>%s", align("Curative Herbs", {width = Stygian.info.wordwrap})))
  cecho("infoHerbs", Stygian_curingHerbPrint("arnica", "calamus"))
  cecho("infoHerbs", Stygian_curingHerbPrint("chervil", "coltsfoot"))
  cecho("infoHerbs",  Stygian_curingHerbPrint("earwort", "faeleaf"))
  cecho("infoHerbs",  Stygian_curingHerbPrint("galingale", "horehound"))
  cecho("infoHerbs",  Stygian_curingHerbPrint("kafe", "kombu"))
  cecho("infoHerbs",  Stygian_curingHerbPrint("marjoram", "myrtle"))
  cecho("infoHerbs",  Stygian_curingHerbPrint("pennyroyal", "reishi"))
  cecho("infoHerbs",  Stygian_curingHerbPrint("sparkleberry", "wormwood"))
  cecho("infoHerbs",  Stygian_curingHerbPrint("yarrow"))
  cecho("infoHerbs", string.format("\n<purple>%s", align("Functional Herbs", {width = Stygian.info.wordwrap - 1})))
  cecho("infoHerbs",  Stygian_functionalHerbPrint("colewort", "flax"))
  cecho("infoHerbs",  Stygian_functionalHerbPrint("juniper", "merbloom"))
  cecho("infoHerbs",  Stygian_functionalHerbPrint("mistletoe", "rosehips"))
  cecho("infoHerbs",  Stygian_functionalHerbPrint("sage", "sargassum"))
  cecho("infoHerbs",  Stygian_functionalHerbPrint("weed"))
end
function Stygian_updateAstro()
  clearUserWindow("infoAstro")
  cecho("infoAstro", string.format("<red>%s\n", align("Ray effects", {width = 34})))
  for i,sign in ipairs(Stygian.astrology.numtoSign) do
    Stygian.astrology[sign] = {}
  end
  for planet,sign in pairs(Stygian.astrology.stargaze) do
    table.insert(Stygian.astrology[sign], planet)
  end
  
  for i,sign in ipairs(Stygian.astrology.numtoSign) do
    if #Stygian.astrology[sign] > 0 then
      cecho("infoAstro", string.format("<purple>%s<green>%s\n", sign, Stygian_signRayEffect(sign)))
    else
      cecho("infoAstro", string.format("<purple>%s<green>:No effects\n", sign))
    end
  end
  cecho("infoAstro", string.format("<red>%s\n", align("Sphere Effects", {width = "34"})))
  cecho("infoAstro", string.format("<brown>%s|Str|Dur|mp |wp |enp|Ran|Pow\n", align("Affects", {width = 9, alignment="left"})))

  for i,sign in ipairs(Stygian.astrology.numtoSign) do
    local sun = Stygian_astroEffect(sign, Stygian.astrology.stargaze.Sun)
    local moon = Stygian_astroEffect(sign, Stygian.astrology.stargaze.Moon)
    local eroee = Stygian_astroEffect(sign, Stygian.astrology.stargaze.Eroee)
    local sidiak = Stygian_astroEffect(sign, Stygian.astrology.stargaze.Sidiak)
    local tarox = Stygian_astroEffect(sign, Stygian.astrology.stargaze.Tarox)
    local papaxi = Stygian_astroEffect(sign, Stygian.astrology.stargaze.Papaxi)
    local aapek = Stygian_astroEffect(sign, Stygian.astrology.stargaze.Aapek)
    cecho("infoAstro", string.format("<purple>%s\n", sign))
    cecho("infoAstro", string.format("<green>%s|%s |%s |%s |%s |%s |%s |%s\n", align(Stygian.astrology.sphereEffects[sign],{width = 9, alignment="left"}),sun,moon,eroee,sidiak,tarox,papaxi,aapek))
  end
end
